import { reqAddressInfo, reqOrderInfo } from "@/api";


//仓库
//actions：处理actions，可以书写自己的业务逻辑，也可以处理异步
const actions = {
    async getAddressInfo({ commit }) {
        let result = await reqAddressInfo()
        // console.log(result);
        commit('GETADDRESSINFO', result.data)
    },
    //获取购物车的商品的数据
    async getOrderInfo({ commit }) {
        let result = await reqOrderInfo()
        // console.log(result);
        if (result.code == 200) {
            commit("GETORDERINFO", result.data)
        }
    }
};

//mutations：修改state的唯一手段
const mutations = {
    GETADDRESSINFO(state, address) {
        state.address = address
    },
    GETORDERINFO(state, orderInfo) {
        state.orderInfo = orderInfo
    }
};

//state:仓库存储数据的地方
const state = {
    address: [],
    orderInfo: []
};

//getters：理解为计算属性，可以简化仓库数据，让组件获取仓库的数据更加方便
//将Search的需要用到的state数据简化的此处
const getters = {
};


export default {
    actions,
    mutations,
    state,
    getters
}
